package com.gm.nanopct3.test;

import com.friendlyarm.AndroidSDK.HardwareControler;
import com.gm.nanopct3.tools.Freq;

/**
 * Created by Mouse on 2017/8/19.
 */

public class LiangLiang extends Thread {


    private static final int interval = 300;

    int pin;

    public LiangLiang(int pin) {
        this.pin = pin;
    }

    @Override
    public void run() {
        try {
            word1();
            word2();
            word3();
            word4();
            word5();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    private void word1() throws InterruptedException {

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL6));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM2));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM2));
        sleep(interval);

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval * 2);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL6));
        sleep(interval * 4);
        HardwareControler.PWMStopEx(pin);
        sleep(interval);
    }

    private void word2() throws InterruptedException {

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL7));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL7));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL7));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM1));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL7));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL3));
        sleep(interval * 2);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL5));
        sleep(interval);

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL6));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL5));
        sleep(interval * 4);
        HardwareControler.PWMStopEx(pin);
        sleep(interval);
    }

    private void word3() throws InterruptedException {

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CL6));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM2));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM2));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);

        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval * 3);
        HardwareControler.PWMStopEx(pin);
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM2));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM3));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
    }

    private void word4() throws InterruptedException {
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM6));
        sleep(interval * 3);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM6));
        sleep(interval * 3);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
    }

    private void word5() throws InterruptedException {
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM5));
        sleep(interval);
        HardwareControler.PWMPlayEx(pin, getFerq(Freq.CM6));
        sleep(interval * 4);
        HardwareControler.PWMStopEx(pin);
        sleep(interval);
    }

    private int getFerq(Freq f) {
        return (int) f.getFreq();
    }

}
